import java.time.DayOfWeek;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author： pang-yun
 * @date： 2021-11-22 09:19
 * 功能目的 ：用于   9 -30 定时任务
 */

public class ScheduleTask {
    public static void main(String[] args) {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime need = now.withHour(9).withMinute(30).withSecond(0).withNano(0).with(DayOfWeek.MONDAY);
        Duration between = Duration.between(now, need);

        ScheduledExecutorService pool = Executors.newScheduledThreadPool(1);
        AtomicInteger integer = new AtomicInteger(1);
        pool.scheduleAtFixedRate(()->{
            System.out.println(integer.getAndIncrement() + " -> " + LocalDateTime.now());
        },between.toMillis(),1000, TimeUnit.MILLISECONDS);

    }
}
